import { baseUrl } from './config';


export default (url, path) => {
    return new Promise((resolve, reject) => {
        const access_token = uni.getStorageSync('token');
        uni.uploadFile({
            url: `${baseUrl}${url}`,
            filePath: path,
            name: 'file',
            header: {
                'token': access_token
            },
            success: (res) => {
                try {
                    const data = JSON.parse(res.data);
                    resolve(data);
                } catch (err) {
                    reject(res);
                }
            },
            fail: (err) => {
                console.log('上传失败', err);
                uni.showToast({
                    icon: 'error',
                    title: '上传失败'
                })
                reject(err);
            }
        })
    })
}